package com.xh.common.thread;

import com.xh.common.thread.ctl.ThreadPool;

import java.util.concurrent.Executor;

public class AsyncExecutor {

    public static final String DEFAULT = "default";

    public static void execute(Runnable runnable) {
        ThreadPool.getDefaultExecutor().execute(runnable);
    }

    public static void execute(Runnable runnable, Priority priority) {
        ThreadPool.getDefaultExecutor().execute(runnable, priority);
    }

    public static void execute(Runnable runnable, String group, int limitSize) {
        ThreadPool.getDefaultExecutor().execute(runnable, group, limitSize);
    }

    public static void execute(Runnable runnable, Priority priority, String group, int limitSize) {
        ThreadPool.getDefaultExecutor().execute(runnable, group, limitSize, priority);
    }

    public static void executeSerial(Runnable runnable) {
        ThreadPool.getDefaultExecutor().execute(runnable, DEFAULT, 1);
    }

    public static void executeSerial(Runnable runnable, String group) {
        ThreadPool.getDefaultExecutor().execute(runnable, group, 1);
    }

    public static void executeSerial(Runnable runnable, String group, Priority priority) {
        ThreadPool.getDefaultExecutor().execute(runnable, group, 1, priority);
    }


    /**
     * 获取默认线程池
     */
    public static Executor getDefaultExecutor() {
        return ThreadPool.getDefaultExecutor();
    }

    /**
     * 获取无限制的线程池，目前只由于文件的下载
     */
    public static Executor getCacheExecutor() {
        return ThreadPool.getCacheExecutor();
    }
}
